#include <stdio.h>

#include "main.h"

#ifdef __GNUC__
	#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
	#define GETCHAR_PROTOTYPE int __io_getchar(FILE *f)
#else
	#define PUTCHAR_PROTOTYPE  int fputc(int ch, FILE *stream)
	#define GETCHAR_PROTOTYPE int fgetc(FILE *f)
#endif

#if IO_USE_HAL
	PUTCHAR_PROTOTYPE
	{
	  HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, HAL_MAX_DELAY);
	  return ch;
	}

	GETCHAR_PROTOTYPE
	{
	  uint8_t  ch;
	  HAL_UART_Receive(&huart1,(uint8_t *)&ch, 1, HAL_MAX_DELAY);
	  return  ch;
	}
#else
	PUTCHAR_PROTOTYPE
	{
		while((USART1->SR & UART_FLAG_TC) == RESET);
		USART1->DR=(uint8_t)ch;
		return ch;
	}

	GETCHAR_PROTOTYPE
	{
		while((USART1->SR & UART_FLAG_RXNE) == RESET);
		return (uint8_t)(USART1->DR);
	}
#endif
